package com.carkeeper.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carkeeper.entity.AccountsPO;
import com.carkeeper.service.AccountsService;
import com.carkeeper.service.StoreFeign;
import com.carkeeper.vo.AccountsVO;
import com.carkeeper.vo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/accounts")
public class AccountController {
    @Autowired
    private AccountsService accountsService;
    @Autowired
    private StoreFeign storeFeign;
    /*
    * 新增结算单
    * */
    @PostMapping()
    public String addAccounts(@RequestBody AccountsPO accountsPO){
        try {
            accountsService.addAccounts(accountsPO);
            return "新增成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "新增失败";
        }
    }
    /*
     * 获取结算单分页
     * */
    @GetMapping
    public Pager<AccountsPO> getAccountPage(@RequestBody AccountsVO accountsVO){
        Page<AccountsPO> poPage = new Page<>(accountsVO.getPage(),accountsVO.getPagesize());
        Pager<AccountsPO> pager = accountsService.getAccountPage(poPage);
        return pager;
    }
    /*
     * 获取结算单详情
     * */
    @GetMapping("/{id}")
    public AccountsPO getAccount(@PathVariable("id") Long id){
        AccountsPO accounts = accountsService.getAccounts(id);
        return accounts;
    }
    /*
    * 删除结算单
    * */
    @DeleteMapping("/{id}")
    public String del(@PathVariable("id") Long id){
        try {
            accountsService.del(id);
            return "删除成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "删除失败";
        }
    }
}
